<%@ page import="com.onlinevideo.entity.User" %>
<%@ page import="com.onlinevideo.service.impl.HistoryServiceImpl" %>
<%@ page import="com.onlinevideo.entity.History" %>
<%@ page import="java.util.List" %>
<%@ page import="com.onlinevideo.service.impl.VideoServiceImpl" %>
<%@ page import="com.onlinevideo.entity.Video" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
    <script type="text/javascript" src="../static/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="../static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../static/js/sweetalert.min-2.1.2.js" ></script>
    <script type="text/javascript" src="../static/js/jquery-1.11.3.min.js"></script>
    <style type="text/css">
        .gro{
            margin-bottom: 0px;
        }
        body::-webkit-scrollbar {
            display: none; /*隐藏滚动条*/
        }
        .rows{
            border-bottom: 2px solid black;
            margin-top: 5px;
            margin-bottom: 15px;
            padding-bottom:5px ;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $("#deleteHistory").click(function () {
                $.ajax({
                    url:"../history.do",
                    type:"POST",
                    data:{
                        action:"deleteHistory"
                    },
                    success:function (data) {
                        var result = JSON.parse(data);
                        if (result.code===1){
                            swal("提示", result.message, "success").then(function (isOk) {
                                window.location.reload();
                            });
                        }else {
                            swal("警告", result.message, "error").then(function (isOk) {});
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>
    <div style="height: 50px;width: 100%;background-color:#3a69a5;border: 1px solid #000000">
        <span style="font-size: 30px;color: #dddddd">历史记录</span><button id="deleteHistory" style="position: relative;top: -2px;left: 20px;
">删除历史记录</button>
    </div>
    <div class="container-fluid">
        <%
            User user = (User) session.getAttribute("user");
            if (user == null) {
                user = new User();
                user.setId(1L);
            }
            HistoryServiceImpl historyService = new HistoryServiceImpl();
            VideoServiceImpl videoService = new VideoServiceImpl();
            List<History> histories = historyService.queryByUser(user.getId());
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (int i = 0; i < histories.size(); i++) {
                History history = histories.get(i);
                Video video = videoService.queryById(history.getVideoId());

        %>
        <div class="row rows" >
            <div class="col-md-3 col-sm-3">
                <div class="form-group gro">
                    <a target="_blank" href="../video.do?action=play&videoId=<%=video.getId()%>">
                        <img src="<%=video.getVideoImg()%>" style="width: 175px;height: 100px;" class="img-responsive" alt="Responsive image">
                    </a>
                </div>
            </div>
            <div class="col-md-8 col-sm-8">
                <div class="form-group gro">
                    <h4 style="font-weight: bold;font-size: 1.17em"><%=video.getVideoName()%></h4>
                    <h5 style="font-size: 14px"><%=video.getVideoDescription()%></h5>
                    <h5 style="font-size: 14px"><%= simpleDateFormat.format(Long.valueOf(video.getUploadTime()))  %></h5>
                </div>
            </div>
        </div>
        <%
            }
        %>


    </div>
</body>
</html>
